var t = require("../../../@babel/runtime/helpers/defineProperty"), e = getApp();

Page({
    data: {
        bannerindex: 1,
        info: {},
        mainCommentShow: !1,
        maincomment: "",
        uName: null,
        commentId: null,
        activeTid: null,
        isUnsubscribe: !1,
        UnsubscribeId: null,
        page: 1,
        isLoadMore: !0,
        total_page: 0,
        isNOMore: !1
    },
    onLoad: function(t) {
        this.getData();
    },
    onReady: function() {},
    onShow: function() {},
    getData: function() {
        var t = this, a = e.getNetAddresss("plugin.micro-communities.api.trick.getFollowTrick");
        e._getNetWork({
            url: a,
            success: function(e) {
                var a = e.data;
                1 === a.result ? (a.data.data.forEach(function(e) {
                    e.created_at = t.timeSlice(e.created_at);
                }), t.setData({
                    isLoadMore: !0,
                    total_page: a.data.last_page,
                    uName: a.data.uName,
                    info: a.data.data
                })) : wx.showToast({
                    title: a.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    showUnsubscribe: function(t) {
        var e = t.currentTarget.dataset.stickid;
        this.setData({
            UnsubscribeId: e,
            isUnsubscribe: !0
        });
    },
    isCoverLayer: function() {
        this.setData({
            mainCommentShow: !1,
            isUnsubscribe: !1
        });
    },
    UnsubscribeMethob: function() {
        var t = this, a = e.getNetAddresss("plugin.micro-communities.api.user.delFollow"), i = {
            uid: this.data.UnsubscribeId
        };
        e._getNetWork({
            url: a,
            data: i,
            success: function(e) {
                var a = e.data;
                1 === a.result ? (wx.showToast({
                    title: "已取消关注",
                    icon: "none",
                    duration: 1500
                }), t.setData({
                    isUnsubscribe: !1
                }), t.getData()) : wx.showToast({
                    title: a.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    toEdit: function() {
        wx.navigateTo({
            url: "/packageC/micro_communities/microRelease/microRelease"
        });
    },
    gotoMicrocommentdetails: function(t) {
        var e = t.currentTarget.dataset.stickid;
        console.log(e, "stick_id"), wx.navigateTo({
            url: "/packageC/micro_communities/microCommentDetails/microCommentDetails?stickId=" + e
        });
    },
    selectLike: function(a) {
        var i = a.currentTarget.dataset.item, n = i.id, o = i.is_praise, s = a.currentTarget.dataset.index, c = this;
        if (1 == o) {
            var r = e.getNetAddresss("plugin.micro-communities.api.trick.cancelPraise"), u = {
                tid: n
            };
            e._getNetWork({
                url: r,
                data: u,
                success: function(e) {
                    var a = e.data;
                    1 === a.result ? (wx.showToast({
                        title: "取消点赞",
                        icon: "none",
                        duration: 1500
                    }), c.setData(t({}, "info[".concat(s, "].is_praise"), 0))) : wx.showToast({
                        title: a.msg,
                        icon: "none",
                        duration: 1500
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        } else {
            var m = e.getNetAddresss("plugin.micro-communities.api.trick.givePraise"), d = {
                tid: n
            };
            e._getNetWork({
                url: m,
                data: d,
                success: function(e) {
                    var a = e.data;
                    1 === a.result ? (wx.showToast({
                        title: "点赞成功",
                        icon: "none",
                        duration: 1500
                    }), c.setData(t({}, "info[".concat(s, "].is_praise"), 1))) : wx.showToast({
                        title: a.msg,
                        icon: "none",
                        duration: 1500
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    sidingsImg: function(t) {
        var e = t.detail.current;
        this.setData({
            bannerindex: e + 1
        });
    },
    maincommentinp: function(t) {
        var e = t.detail.value;
        this.setData({
            maincomment: e
        });
    },
    subMainCommentBtn: function(t) {
        var e = t.currentTarget.dataset.id, a = t.currentTarget.dataset.ind;
        this.setData({
            commentId: e,
            maincomment: "",
            activeTid: a,
            mainCommentShow: !0
        });
    },
    subMainBtn: function() {
        this.data.maincomment ? (this.setData({
            mainCommentShow: !1
        }), this.getReplyComments()) : wx.showToast({
            title: "请输入你的精彩评论",
            icon: "none",
            duration: 1500
        });
    },
    getReplyComments: function() {
        var t = this, a = e.getNetAddresss("plugin.micro-communities.api.trick.comments"), i = {
            tid: t.data.commentId,
            content: t.data.maincomment
        };
        e._postNetWork({
            url: a,
            data: i,
            success: function(e) {
                var a = e.data;
                1 === a.result ? (t.data.info[t.data.activeTid].comment.unshift({
                    content: t.data.maincomment,
                    uname: t.data.uName
                }), t.setData({
                    info: t.data.info
                }), wx.showToast({
                    title: a.msg,
                    icon: "none",
                    duration: 1500
                })) : wx.showToast({
                    title: a.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    gotoHome: function(t) {
        var e = t.currentTarget.dataset.micuid;
        wx.redirectTo({
            url: "/packageC/micro_communities/microhomepage/microhomepage?micuid=" + e
        });
    },
    getMoreData: function() {
        var t = this;
        if (t.setData({
            isLoadMore: !1
        }), !(this.data.page >= this.data.total_page)) {
            t.setData({
                page: this.data.page + 1
            });
            var a = e.getNetAddresss("plugin.micro-communities.api.trick.getFollowTrick"), i = {
                page: t.data.page
            };
            e._getNetWork({
                url: a,
                data: i,
                success: function(e) {
                    var a = e.data;
                    if (t.setData({
                        isLoadMore: !0
                    }), 1 === a.result) {
                        var i = a.data.data;
                        i.forEach(function(e) {
                            e.created_at = t.timeSlice(e.created_at);
                        }), t.setData({
                            info: t.data.info.concat(i)
                        });
                    } else t.setData({
                        page: t.data.page - 1,
                        isLoadMore: !1
                    }), wx.showToast({
                        title: a.msg,
                        icon: "none",
                        duration: 1500
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    timeSlice: function(t) {
        var e = 864e5, a = new Date(t), i = new Date().getTime() - a;
        if (i < 0) return "结束日期不能小于开始日期！";
        var n = i / 2592e6, o = i / (7 * e), s = i / e, c = i / 36e5, r = i / 6e4;
        return n >= 1 && n <= 3 || o >= 1 && o <= 3 || s >= 1 && s <= 6 ? t.substr(5, 11) : c >= 1 && c <= 23 ? parseInt(c) + "小时前" : r >= 1 && r <= 59 ? "今天" + parseInt(r) + "分钟前" : i >= 0 && i <= 6e4 ? "刚刚" : t.substr(5, 11);
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多了");
    },
    onShareAppMessage: function() {},
    onShareTimeline: function() {}
});